package com.hankkin.reading.greendao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

import com.hankkin.reading.domain.WebExplain;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "WEB_EXPLAIN".
*/
public class WebExplainDao extends AbstractDao<WebExplain, Long> {

    public static final String TABLENAME = "WEB_EXPLAIN";

    /**
     * Properties of entity WebExplain.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "id", true, "_id");
        public final static Property Key = new Property(1, String.class, "key", false, "KEY");
        public final static Property Means = new Property(2, String.class, "means", false, "MEANS");
    }

    private final StringConverter meansConverter = new StringConverter();
    private Query<WebExplain> translateBean_WebExplainsQuery;

    public WebExplainDao(DaoConfig config) {
        super(config);
    }
    
    public WebExplainDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"WEB_EXPLAIN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY NOT NULL ," + // 0: id
                "\"KEY\" TEXT," + // 1: key
                "\"MEANS\" TEXT);"); // 2: means
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"WEB_EXPLAIN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, WebExplain entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
 
        String key = entity.getKey();
        if (key != null) {
            stmt.bindString(2, key);
        }
 
        List means = entity.getMeans();
        if (means != null) {
            stmt.bindString(3, meansConverter.convertToDatabaseValue(means));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, WebExplain entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
 
        String key = entity.getKey();
        if (key != null) {
            stmt.bindString(2, key);
        }
 
        List means = entity.getMeans();
        if (means != null) {
            stmt.bindString(3, meansConverter.convertToDatabaseValue(means));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    @Override
    public WebExplain readEntity(Cursor cursor, int offset) {
        WebExplain entity = new WebExplain( //
            cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // key
            cursor.isNull(offset + 2) ? null : meansConverter.convertToEntityProperty(cursor.getString(offset + 2)) // means
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, WebExplain entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setKey(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setMeans(cursor.isNull(offset + 2) ? null : meansConverter.convertToEntityProperty(cursor.getString(offset + 2)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(WebExplain entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(WebExplain entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(WebExplain entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "webExplains" to-many relationship of TranslateBean. */
    public List<WebExplain> _queryTranslateBean_WebExplains(long id) {
        synchronized (this) {
            if (translateBean_WebExplainsQuery == null) {
                QueryBuilder<WebExplain> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Id.eq(null));
                translateBean_WebExplainsQuery = queryBuilder.build();
            }
        }
        Query<WebExplain> query = translateBean_WebExplainsQuery.forCurrentThread();
        query.setParameter(0, id);
        return query.list();
    }

}
